<template>
    <div>
        <el-upload
            class="avatar-uploader"
            action="http://localhost:8081/upload/uploadFileTencentCos"
            :show-file-list="false"
            :on-success="handleAvatarSuccess"
            type="file" name="multipartFile"
        >
          <img v-if="imageUrl" :src="imageUrl" class="avatar" alt="头像" />
          <el-icon v-else class="avatar-uploader-icon"><Plus/></el-icon>
        </el-upload>
    
    </div>
    </template>
    
    <script>
    import { toRefs,reactive} from 'vue'
    
    // const {ElMessage} = require("element-plus");
    
    export default {
      name: "toUpLoad",
      setup(props, {emit}) {
        //我们这里仅用到了emit
        // 向父组件发送数据
        const update = (url) => {
          // 第一个参数: 事件名
          // 第二个参数: 数据
          emit('send', url)
        }
    
        const data = reactive({
          imageUrl:"",
        })
    
        const handleAvatarSuccess =(res)=>{
         let url = data.imageUrl = res.data.filePath
          // data.updateForm.adminId = JSON.parse(localStorage.getItem('setUser')).adminId
          // data.updateForm.filepath = res.data.filepath
          update(url)
          // console.log("res------>",res)
        }
    
    
    
    
    
        return{
          ...toRefs(data),
          handleAvatarSuccess,
          update
        }
      }
    }
    </script>
    
    <style>
    .avatar-uploader .avatar {
      width: 178px;
      height: 178px;
      display: block;
    }
    .avatar-uploader el-upload {
      border: 1px dashed var(--el-border-color);
      border-radius: 6px;
      cursor: pointer;
      position: relative;
      /*overflow: hidden;*/
      transition: var(--el-transition-duration-fast);
    }
    
    .avatar-uploader el-upload:hover {
      border-color: var(--el-color-primary);
    }
    
    .el-icon.avatar-uploader-icon {
      font-size: 28px;
      color: #8c939d;
      width: 178px;
      height: 178px;
      text-align: center;
    }
    </style>
    <style scoped>
    .avatar-uploader .avatar {
      width: 178px;
      height: 178px;
      display: block;
    }
    </style>